package A002lock8;


import java.util.concurrent.TimeUnit;

// 新增普通的hello方法，请问先打印邮件还是hello
// -----sayHello
// -----sendEmail

class Phone03 {
    public synchronized void sendEmail() throws Exception {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("-----sendEmail");
    }

    public void sayHello() {
        System.out.println("-----sayHello");
    }
}

public class A002_线程八锁_3 {
    public static void main(String[] args) throws InterruptedException {

        Phone03 phone03 = new Phone03();

        new Thread(() -> {
            try {
                phone03.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "A").start();

        Thread.sleep(100);

        new Thread(() -> {
            try {
                phone03.sayHello();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "B").start();
    }
}

